package com.api.regression.group.getgroup;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.api.test.AssertApi;
import com.zyncro.api.IGroupApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.GroupApi;
import com.zyncro.api.model.GroupApiType;
import com.zyncro.api.model.ObjectResultApi;

@ContextConfiguration(locations = { "classpath:/group/group-context.xml" })
public class GetGroup extends AbstractApiTest {

	@Value("#{staticgroups['user.getGroups'].appId}")
	private String userUrn;

	@Value("#{staticgroups['user.getGroups'].password}")
	private String userPassword;

	@Value("#{staticgroups['group.companyFeed.urn']}")
	private String companyFeedUrn;

	@Value("#{staticgroups['group.personalFeed.urn']}")
	private String personalFeedUrn;

	@Value("#{staticgroups['group.open.notMember.urn']}")
	private String openGroupUrn;

	@Value("#{staticgroups['group.external.urn']}")
	private String externalGroupUrn;

	@Value("#{staticgroups['group.tag.urn']}")
	private String tagGroupUrn;

	@BeforeClass
	protected void loginUser() throws Exception {

		getApi().login(userUrn, userPassword);
	}

	@Test
	public void testGetCompanyFeedGroup() throws ZyncroApiException {

		ObjectResultApi<GroupApi> result = getApi().getService(IGroupApiService.class).getGroup(companyFeedUrn);
		GroupApi group = result.getObject();

		AssertApi.assertApiType(group.getShareGroupType(), GroupApiType.COMPANY_FEED);
	}

	@Test
	public void testGetPersonalFeedGroup() throws ZyncroApiException {

		ObjectResultApi<GroupApi> result = getApi().getService(IGroupApiService.class).getGroup(personalFeedUrn);
		GroupApi group = result.getObject();

		AssertApi.assertApiType(group.getShareGroupType(), GroupApiType.PERSONAL_FEED);
	}

	@Test
	public void testGetOpenGroup() throws ZyncroApiException {

		ObjectResultApi<GroupApi> result = getApi().getService(IGroupApiService.class).getGroup(openGroupUrn);
		GroupApi group = result.getObject();

		AssertApi.assertApiType(group.getShareGroupType(), GroupApiType.GROUP);
	}

	@Test
	public void testGetExternalGroup() throws ZyncroApiException {

		ObjectResultApi<GroupApi> result = getApi().getService(IGroupApiService.class).getGroup(externalGroupUrn);
		GroupApi group = result.getObject();

		AssertApi.assertApiType(group.getShareGroupType(), GroupApiType.GROUP);
	}

	@Test(expectedExceptions = ZyncroApiException.class)
	public void testGetTagGroup() throws ZyncroApiException {

		getApi().getService(IGroupApiService.class).getGroup(tagGroupUrn);
	}
}
